package com.example.xpvideo.Controller;

import com.example.xpvideo.entity.LsHotTradingArea;
import com.example.xpvideo.entity.ResponseResult;
import com.example.xpvideo.service.LsHotTradingAreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author hjt
 * @create 2021-09-01 15:14
 * @describe：热门商圈
 */
@RestController
@RequestMapping("hotTrading")
public class HotTradingAreaController {
    @Autowired
    private LsHotTradingAreaService hotTradingAreaService;

    /**
     * 添加热门商圈
     * @param hotTradingArea
     * @param file
     * @return
     */
    @PostMapping("addHotTrading")
    public ResponseResult addHotTrading(@Validated LsHotTradingArea hotTradingArea, MultipartFile file) {
        return hotTradingAreaService.addOrUpdateHotTrading(hotTradingArea, file);
    }

    /**
     * 删除热门商圈
     * @param id
     * @return
     */
    @DeleteMapping("delHotTrading/{id}")
    public ResponseResult delHotTrading(@PathVariable("id") Integer id) {
        return hotTradingAreaService.delHotTrading(id);
    }

    /**
     * 修改热门商圈
     * @param hotTradingArea
     * @return
     */
    @PutMapping("updateHotTrading")
    public ResponseResult updateHotTrading(LsHotTradingArea hotTradingArea,@RequestParam(value = "file",required = false)MultipartFile file) {
        return hotTradingAreaService.addOrUpdateHotTrading(hotTradingArea, file);
    }

    /**
     * 查询所有热门商圈
     * @return
     */
    @GetMapping("findHotTrading")
    public ResponseResult findHotTrading() {
        List<LsHotTradingArea> list = hotTradingAreaService.list();
        return ResponseResult.responseResult(0, list);
    }
}
